﻿/*
 * 版 本 V1.0
 * Copyright (c) 2013-2018 广州市同慧信息科技有限公司
 * 创建人：ftquan
 * 日 期：2017.04.17
 * 描 述：自定义查询
 */
var tableName = request('tableName');
var dbKey = request('dbKey');

var bootstrap = function ($, learun) {
    "use strict";

    var fieldData;

    var page = {
        init: function () {
            page.bind();
        },
        bind: function () {
            //获取字段数据
            learun.httpAsync('GET', config.base_server() + 'dbTables/listFields?dbKey=' + dbKey + '&access_token=' + config.getToken().access_token, {tableName: tableName}, function (data) {
                fieldData = data;
                $('#field').lrselectRefresh({
                    data: fieldData
                });
                var headData = [];

                for (var i = 0, l = data.length; i < l; i++) {
                    var item = data[i];
                    var point = {
                        label: item.columnComment,
                        name: item.columnName.toLowerCase(),
                        width: 150,
                        align: "left"
                    };
                    headData.push(point);
                }
                $('#gridtable').jfGrid({
                    url: config.base_server() + 'dbTables/getTableData?access_token=' + config.getToken().access_token,
                    headData: headData,
                    isPage: true
                });
                page.search();
            });

            // 功能选择
            $('#field').lrselect({
                title: 'columnName',
                text: 'columnComment',
                value: 'columnName',
                maxHeight: 300,
                allowSearch: true
            });

            $('#logic').lrselect({
                maxHeight: 300
            });

            // 查询
            $('#btn_Search').on('click', function () {
                page.search();
            });
        },
        search: function () {
            var param = {};
            param.dbKey = dbKey;
            param.tableName = tableName;

            param.field = $('#field').lrselectGet();
            param.logic = $('#logic').lrselectGet();

            param.keyword = $('#keyword').val();

            $('#gridtable').jfGridSet('reload', param);
        }
    };

    page.init();
}


